function getSidBar() {

    $.post("/messageCenter/messageCenterSidebar",{},function (result){
        if (result.flag){
            for (const resultElement of result.data) {
                var rid = resultElement.id;
                let context = resultElement.context;
                let htmlid = resultElement.htmlid;

                let fun = resultElement.fun;

                var html = '<li  onclick="'+fun+'" class="card_Li01" id="card_Li_0'+rid+'"  >'

                    +'                         <span  class="messageCenterText" id="messageCenterText'+rid+'" >'+context+'</span>'
                    +'<span style="margin-right: -20px;margin-top: -20px;font-size: 10px;float: right;background-color: #fa5a57 ;color: white  ;font-family: \'Microsoft YaHei UI\',serif" name="badge" class="badge badge-light" id="'+htmlid+'" ></span>'
                    +'                     </li>'
                ;

                $("#messageSidBar_ul02").append(html)

            }
            messageCount()
        }

    })



}
function messageCount() {
    /**消息数量小气泡
     * */


    $.post("/messageCenter/messageSideBarCount",{},function (resultCount) {



        let userManageMessageCount = resultCount.userManageMessageCount;
        let businessMessageCount = resultCount.businessMessageCount
        let commonMessageCount = resultCount.commonMessageCount;
        let sysMessageCount = resultCount.sysMessageCount;
        let myMessageCount = resultCount.myMessageCount;


        if (businessMessageCount > 0) {
            if (businessMessageCount < 100) {
                $("#messageCount2").text(businessMessageCount)
            } else {
                $("#messageCount2").text("99+")
            }
        }else {
            $("#messageCount2").hide();
        }

        if (userManageMessageCount > 0) {
            if (userManageMessageCount < 100) {
                $("#messageCount1").text(userManageMessageCount)
            } else {
                $("#messageCount1").text("99+")
            }
        }else {
            $("#messageCount1").hide();
        }

        if (myMessageCount > 0) {
            if (myMessageCount < 100) {
                $("#messageCount3").text(myMessageCount)
            } else {
                $("#messageCount3").text("99+")
            }
        }else {
            $("#messageCount3").hide();
        }

        if (commonMessageCount > 0) {
            if (commonMessageCount < 100) {
                $("#messageCount4").text(commonMessageCount)
            } else {
                $("#messageCount4").text("99+")
            }
        }else {
            $("#messageCount4").hide();
        }

        if (sysMessageCount > 0) {
            if (sysMessageCount < 100) {
                $("#messageCount5").text(sysMessageCount)
            } else {
                $("#messageCount5").text("99+")
            }
        }else {
            $("#messageCount5").hide();
        }


    })
}

function bottomInit(objId) {


    $("#messageSidBar_ul0001").empty()

    let obj = document.getElementById("passButton")
    let obj1 = document.getElementById("ngButton")
    if (obj || obj1) {
        $("#passButton").remove()
        $("#ngButton").remove()
    }

    $.post("/messageCenter/messageCenterSidebar",{},function (result){
        for (const resultElement of result.data) {
            var rid = resultElement.id;
            let str = "card_Li_0"+rid
            if (str !== objId) {
                document.getElementById(str).style.backgroundColor = "rgba(204,204,204,.8)"
                document.getElementById(str).style.color = "#1b1e21"
                document.getElementById(str).style.boxShadow = "0 7px 7px gray"
                document.getElementById(str).style.border = "2px solid white"
                let span = document.getElementById(str).getElementsByTagName("span")
                for (const spanElement of span) {
                    if (spanElement.getAttribute("name") === "badge") {
                        spanElement.removeAttribute("hidden")
                    }
                }
            }
        }})
}

function gotoMessageCenter(){
    window.location.reload(true)
}

function dangerBtn(obj) {
    let arr = obj.split(",")
    let li = arr[1]
    let liId = "card_Li_0001"+li
    let itemName = arr[0]
    $.post("/messageCenter/deleteMessage",{itemName:itemName},function (result) {
        if (result.flag){
            document.getElementById(liId).remove()
            messageCount4(document.getElementById("messageCount4").parentNode)
        }else {
            let message= "刚刚";
            var html = '<div class="toast" role="alert"  data-delay="5000" aria-live="assertive" aria-atomic="true" >'
                +'       <div class="toast-header">'
                +'         <img height="25px" width="25px" src="/static/Img/PageImg/Canva_small.png" class="rounded mr-2" alt="">'
                +'         <strong class="mr-auto" style="color: orange">删除失败</strong>'
                +'          &nbsp;&nbsp;&nbsp;&nbsp;'
                +'         <small class="text-muted">'+message+'</small>'
                +'         <button type="button" class="ml-2 mb-1 close" onclick="deleteToast()" data-dismiss="toast" aria-label="Close">'
                +'           <span aria-hidden="true">&times;</span>'
                +'         </button>'
                +'       </div>'
                +'       <div class="toast-body">'
                +'          &nbsp;&nbsp;&nbsp;&nbsp;'
                +           "删除失败！请联系系统管理员！"
                +'          &nbsp;&nbsp;&nbsp;&nbsp;'
                +'       </div>'
                +'     </div>';
            $("#message_Div").append(html)
            $('.toast').toast("show")
            setTimeout(function () {
                window.location.href = "Spot_Check_Add_Background.html"
            },3000)
        }
        messageCount()
    })
}